﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:vtv="http://schemas.rapidapplicationservices.com/vtv/virtualizedtreeview/">

    <ControlTemplate TargetType="vtv:VirtualizingTreeItem" x:Key="VirtualizedTreeItem">
        <Grid>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal" />
                    <VisualState x:Name="MouseOver">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MouseOverBackground" 
                                                           Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
                            </ObjectAnimationUsingKeyFrames>
                            <DoubleAnimation Storyboard.TargetName="MouseOverBackground" 
                                             Storyboard.TargetProperty="Opacity" To="0.25" 
                                             Duration="0:0:0.15"></DoubleAnimation>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Disabled">
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="SelectionStates">
                    <VisualState x:Name="Unselected">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentBackground" 
                                                           Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0.1" Value="Visible"/>
                            </ObjectAnimationUsingKeyFrames>
                            <DoubleAnimation Storyboard.TargetName="ContentBackground" 
                                             Storyboard.TargetProperty="Opacity" To="0" 
                                             Duration="0:0:0.1"></DoubleAnimation>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Selected">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentBackground" 
                                                           Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
                            </ObjectAnimationUsingKeyFrames>
                            <DoubleAnimation Storyboard.TargetName="ContentBackground" 
                                             Storyboard.TargetProperty="Opacity" To="1" 
                                             Duration="0:0:0.25"></DoubleAnimation>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="FocusStates">
                    <VisualState x:Name="Focused">
                    </VisualState>
                    <VisualState x:Name="Unfocused"/>
                </VisualStateGroup>
                <VisualStateGroup x:Name="ArrowStates">
                    <VisualState x:Name="ArrowMouseOver">
                        <Storyboard>
                            <ColorAnimation Duration="0" Storyboard.TargetName="Arrow" Storyboard.TargetProperty="(Polygon.Fill).(SolidColorBrush.Color)" To="White"/>
                            <ColorAnimation Duration="0" Storyboard.TargetName="Arrow" Storyboard.TargetProperty="(Polygon.Stroke).(SolidColorBrush.Color)" To="#B90E92CA"/>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="ArrowNormal">
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="ExpanderStates">
                    <VisualState x:Name="Expanded">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpandedContentPresenter" 
                                                           Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
                            </ObjectAnimationUsingKeyFrames>
                            <DoubleAnimation Storyboard.TargetName="expanderRotateTransform" 
                                                 Storyboard.TargetProperty="Angle"
                                                 FillBehavior="HoldEnd"
                                                 To="45"
                                                 Duration="0:0:0.2"/>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Collapsed">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CollapsedContentPresenter" 
                                                           Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
                            </ObjectAnimationUsingKeyFrames>
                            <DoubleAnimation Storyboard.TargetName="expanderRotateTransform" 
                                                 Storyboard.TargetProperty="Angle"
                                                 FillBehavior="HoldEnd"
                                                 To="0"
                                                 Duration="0:0:0.2"/>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="14"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>

            <Border x:Name="Expander" 
                    Visibility="{TemplateBinding ExpanderVisibility}"
                    Background="Transparent"  
                    IsHitTestVisible="True" 
                    Grid.Column="0">
                <Polygon x:Name="Arrow" Points="0,0 4,4 0,8" Fill="Black" 
                         Stroke="Transparent" StrokeThickness="0.5"  Margin="5" RenderTransformOrigin="0.5,0.5" 
                             VerticalAlignment="Center"
                             HorizontalAlignment="Center">
                    <Polygon.RenderTransform>
                        <RotateTransform x:Name="expanderRotateTransform"></RotateTransform>
                    </Polygon.RenderTransform>
                </Polygon>
            </Border>

            <Border x:Name="ContentBackground" 
                    BorderBrush="#B90E92CA" 
                    BorderThickness="0.5" 
                    CornerRadius="0" 
                    Grid.Column="1" 
                    Visibility="Collapsed"
                    Opacity="0">
                <Border.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#340E92CA" Offset="0.483"/>
                        <GradientStop Color="#3A0E92CA" Offset="1"/>
                        <GradientStop Color="#200E92CA"/>
                    </LinearGradientBrush>
                </Border.Background>
            </Border>
            <Border x:Name="MouseOverBackground" 
                    BorderBrush="#B90E92CA" 
                    BorderThickness="0.5" 
                    CornerRadius="0" 
                    Grid.Column="1" 
                    Visibility="Collapsed"
                    Opacity="0">
                <Border.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#640E92CA" Offset="0.483"/>
                        <GradientStop Color="#5A0E92CA" Offset="1"/>
                        <GradientStop Color="#400E92CA"/>
                    </LinearGradientBrush>
                </Border.Background>
            </Border>
            <StackPanel Orientation="Horizontal" Grid.Column="1"  Margin="{TemplateBinding Padding}">
                <ContentPresenter x:Name="CollapsedContentPresenter"
                              Visibility="Collapsed"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              ContentTemplate="{TemplateBinding ContentTemplate}"
                              Content="{TemplateBinding Content}"
                              Margin="5,0,5,0"/>
                <ContentPresenter x:Name="ExpandedContentPresenter"
                              Visibility="Collapsed"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              ContentTemplate="{TemplateBinding ExpandedContentTemplate}"
                              Content="{TemplateBinding Content}"
                              Margin="5,0,5,0"/>
            </StackPanel>
        </Grid>
    </ControlTemplate>

    <Style TargetType="vtv:VirtualizingTreeItem">
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="Padding" Value="7,2,7,2"/>
        <Setter Property="Margin" Value="0"/>
        <Setter Property="Template" Value="{StaticResource VirtualizedTreeItem}">
        </Setter>
    </Style>
</ResourceDictionary>
